package syyrjx.controller;

import syyrjx.jdbc.DataBase;
import syyrjx.jdbc.util.JDBCTool;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class DeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.delete(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.delete(request, response);
    }
    private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        if(DataBase.delete(id)) {
            out.print("删除成功");
        }else{
            out.print("删除失败");
        }

    }
}
